package com.acwing.work;

import javax.xml.stream.FactoryConfigurationError;
import java.io.*;
import java.util.Arrays;

/**
 * @author anan
 * @create 2021-08-31 19:37
 */
public class jishui {
    private static int minn(int a, int b, int c, int d){
        int min = Integer.MAX_VALUE;
        min = a < min ? a:min;
        min = b < min ? b:min;
        min = c < min ? c:min;
        min = d < min ? d:min;
        return min;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String s = reader.readLine();
        String[] str = s.split(",");
        int col = str.length;
        str[0] = str[0].substring(1);
        int rowdd = str[0].length();
        str[col - 1] = str[col - 1].substring(0, rowdd);

        int row = str[0].split(" ").length;

        int[][] arr = new int[col][row];
        for (int i = 0; i < col; i++) {
            String[] str2 = str[i].split(" ");
            for (int j = 0; j < row; j++) {
                arr[i][j] = Integer.parseInt(str2[j]);
            }
        }

/*        boolean[][] flag = new boolean[col][row];*/
        int right, down, left, up, min;
        int sum = 0;
        for (int i = 0; i < col; i++) {
            for (int j = 0; j < row; j++) {
                /*flag[i][j] = false;*/
                if (i - 1 >= 0 /*&& flag[i-1][j] == false*/) up = arr[i-1][j];
                else up = Integer.MAX_VALUE;

                if (i + 1 < col) down= arr[i+1][j];
                else down = Integer.MAX_VALUE;

                if (j - 1 >= 0/* && flag[i][j - 1] == false*/) left = arr[i][j - 1];
                else left = Integer.MAX_VALUE;

                if (j + 1 < row) right= arr[i][j + 1];
                else right = Integer.MAX_VALUE;

                min = minn(up, down, right, left);
                if (arr[i][j] < min) {
                    /*flag[i][j] = true;*/
                    sum += (min - arr[i][j]);
                    arr[i][j] = min;
                }

                else if (arr[i][j] == min){

                }
            }
        }
        writer.write(sum + "\n");
        writer.flush();
        writer.close();
        reader.close();

    }
}
